package com.lipei.vrp;

import java.io.File;
import java.io.IOException;
import java.lang.ProcessBuilder.Redirect;
import java.util.ArrayList;

public class Main {

	public static void runSql(String filename) throws IOException,
			InterruptedException {
		String command = "\"" + Context.mysqlexe + "\" -u " + Context.USERNAME
				+ " --password=" + Context.PASSWORD;

		ArrayList<String> commands = new ArrayList<String>();
		commands.add(Context.mysqlexe);
		commands.add("-u");
		commands.add(Context.USERNAME);
		commands.add("--password=" + Context.PASSWORD);
		ProcessBuilder builder = new ProcessBuilder(commands);
		builder.redirectInput(new File(filename));
		builder.redirectOutput(Redirect.PIPE);
		builder.redirectError(Redirect.INHERIT);
		Process pro = builder.start();

		pro.waitFor();

		if (pro.exitValue() != 0) {
			throw new RuntimeException("mysql run error, return is :"
					+ pro.exitValue());
		}
	}
}
